{% from '@SyliusAdmin/shared/helper/breadcrumbs.html.twig' import breadcrumbs %}

{% set configuration = hookable_metadata.context.configuration %}
{% set resource = hookable_metadata.context.resource %}
{% set metadata = hookable_metadata.context.metadata %}

{% set resource_index = metadata.applicationName~'.ui.'~metadata.pluralName %}
{% set index_url = path(
    configuration.vars.index.route.name|default(configuration.getRouteName('index')),
    configuration.vars.index.route.parameters|default(configuration.vars.route.parameters|default({}))
) %}

{% set rendered_field_prefix = hookable_metadata.configuration.rendered_field_prefix|default(null) %}
{% set field_name = hookable_metadata.configuration.rendered_field|default('') %}
{% set rendered_field = rendered_field_prefix ~ (attribute(resource, field_name) is defined ? attribute(resource, field_name) : null) %}

{% set resource_edit_name = rendered_field|default(resource.translations[app.locale].name|default(resource.code|default(resource.id))) %}
{% set show_route_name = configuration.vars.index.route.name|default(configuration.getRouteName('show')) %}

{% if sylius_route_exists(show_route_name) %}
    {% set show_url = path(show_route_name, { id: resource.id }) %}
    {% set resource_edit = { name: resource_edit_name, url: show_url} %}
{% else %}
    {% set resource_edit = { name: resource_edit_name, active: true} %}
{% endif %}

{{ breadcrumbs([
    { name: 'sylius.ui.dashboard', url: path('sylius_admin_dashboard'), active: false },
    { name: resource_index, url: index_url, active: false },
    resource_edit,
    { name: 'sylius.ui.edit'|trans, active: false }
]) }}
